package com.jx.daoimpl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.jx.dao.FindAdminsDao;
import com.jx.model.Admin;
import com.jx.util.JDBCUtil;

import net.sf.json.JSONObject;

public class FindAdminsDaoImpl implements FindAdminsDao{
	/**
	 * 查询全部管理员
	 */
	@Override
	public List<Admin> findAdminDao(int start,int pagesize) {
		// TODO Auto-generated method stub
		List<Admin> admins=new ArrayList<Admin>();
		Connection con=JDBCUtil.getConnection();
		StringBuffer sql=new StringBuffer("select * from j_admin limit ?,?");
		try {
			PreparedStatement pst=con.prepareStatement(sql.toString());
			pst.setInt(1, start);
			pst.setInt(2, pagesize);
			ResultSet rst=pst.executeQuery();
			while(rst.next()){
				Admin admin=new Admin(rst.getInt("aid"),rst.getString("aname"),rst.getString("apsw"),rst.getInt("asex"),rst.getInt("aage"),rst.getString("adep"),rst.getInt("asalary"));
				admins.add(admin);
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return admins;
	}
	/**
	 * 查询管理员总数
	 */
	@Override
	public int findTotalAdmin() {
		// TODO Auto-generated method stub
		int total=0;
		Connection con=JDBCUtil.getConnection();
		StringBuffer sql=new StringBuffer("select count(aid) acount from j_admin");
		try {
			PreparedStatement pst=con.prepareStatement(sql.toString());
			ResultSet res=pst.executeQuery();
			if(res.next()){
				total=res.getInt("acount");
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return total;
	}
}
